home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 26.zip / BS1 part 26 / C for beginners.adf / source / copier.c < prev    next >
C/C++ Source or Header  |  1978-01-17  |  1KB  |  52 lines

  1. /* copier.c 23.2.1 */
  2. #include <stdio.h>
  3.  
  4. main(argc, argv)
  5. int argc;
  6. char *argv[];
  7. {
  8.        long copy(); /*If it is interesting */
  9.  
  10.        if(argc !=3)
  11.           {
  12.               printf("Bad Arguments!\n");
  13.               printf("From_file to_file\n");
  14.           }
  15.        else
  16.          copy(argv[1], argv[2]);
  17. }
  18.  
  19.  
  20. copy(fromfile, tofile) /* Copy Routine */
  21. char *fromfile, *tofile;
  22. {
  23.        FILE *input, *output, *fopen();
  24.        register long counter = 0;
  25.        register int c;
  26.  
  27.        if(!(input = fopen(fromfile, "rb"))) 
  28.         /* Open as Binary        file */
  29.          {
  30.            printf("%s can not be opened!\n", fromfile);
  31.            return 0L;
  32.          }
  33.        if(!(output = fopen(tofile, "wb")))
  34.          {
  35.            printf("%s can not be opened!\n", tofile);
  36.            fclose(input); /* Was OK */
  37.            return 0L;
  38.          }
  39.  
  40.        while( (c = fgetc(input)) !=EOF)
  41.         {
  42.           fputc( c, output);
  43.           counter++;
  44.         }
  45.  
  46.        fclose(input);
  47.        fclose(output);
  48.        printf("\n%ld Bytes copied!\n", counter);
  49.        return(counter);
  50. }
  51.  
  52.